package com.elong.businesstravel.modules.home.adapter;

import java.util.List;

import com.elong.businesstravel.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class SimpleListAdapter extends BaseAdapter {
	
	private List<String> mStrings;
	private Context mContext;
	private String mSelect;
	/**是否显示右边的箭头*/
	private boolean mFlagRightArrow = false;
	
	public SimpleListAdapter(Context context, List<String> strings, String select) {
		mContext = context;
		mStrings = strings;
		mSelect = select;
	}
	
	public SimpleListAdapter(Context context, List<String> strings, String select, boolean rightArrow) {
		mContext = context;
		mStrings = strings;
		mSelect = select;
		mFlagRightArrow = rightArrow;
	}

	@Override
	public int getCount() {
		return mStrings.size();
	}

	@Override
	public Object getItem(int position) {
		return mStrings.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		if(null == convertView){
			convertView = LayoutInflater.from(mContext).inflate(R.layout.view_simple_item, null);
		}
		
		TextView itemTextView = (TextView)convertView.findViewById(R.id.itemTextView);
		itemTextView.setText(mStrings.get(position));
		
		ViewGroup simpleLayout = (ViewGroup)convertView.findViewById(R.id.simpleLayout);
		if(mSelect.equals(mStrings.get(position))){
			simpleLayout.setSelected(true);
		}else {
			simpleLayout.setSelected(false);
		}
		
		ImageView rightArrowImageView = (ImageView)convertView.findViewById(R.id.rightImageView);
		if(mFlagRightArrow){
			rightArrowImageView.setVisibility(View.VISIBLE);
		}else {
			rightArrowImageView.setVisibility(View.GONE);
		}
		
		return convertView;
	}

}
